package com.tengju.user.infrastructure.listener;


import com.tengju.user.domain.shared.DomainEvent;
import com.tengju.user.domain.shared.SpringEvent;

public interface DomainEventListener {

    default <T extends DomainEvent> T checkDomainEvent(SpringEvent springEvent, Class<T> clazz) {

        if (springEvent == null || !(clazz.getName().equalsIgnoreCase(springEvent.getDomainEvent().getClass().getName()))) {
            return null;
        }

        return clazz.cast(springEvent.getDomainEvent());
    }
}
